package com.hexb
{
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;
	
	import mx.controls.Alert;
	import mx.rpc.xml.SimpleXMLEncoder;

	public class Utils
	{
		public function Utils()
		{
		}
		
		/**
		 * 返回格式化字符串
		 * 用于拼合字符串时，传递可变参数
		 * pattern : 如 ：{0}获得了奖励{1}:{2},传入参数 张三，金币，1000 
		 * */
		public static function formatString(pattren:String,...args):String{
			var resulstString:String  = pattren;
			var length:int = args.length ;
			var temp:String = "" ;
			for(var i:int=0 ;i<length;i++){
				temp = "{"+i+"}" ;
				resulstString = resulstString.replace(temp,args[i]);
			}
			return resulstString ;
		}
		
		public static function writeXML(obj:Object):void{
			try{
				var qName:QName = new QName("Root");
				var xmlDoc:XMLDocument = new XMLDocument() ;
				var xmlEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDoc);
				var xmlNode:XMLNode = xmlEncoder.encodeValue(obj,qName,xmlDoc);
				var xml:XML = new XML(xmlDoc.toString());
				Alert.show(xml);
			}catch(e:Error){
				Alert.show(e.message);
			}
		}
	}
}